package com.flash.InventoryManagement.service.impl;

import com.flash.InventoryManagement.entity.SecurityAccrualStock;
import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.mapper.SecurityAccrualStockMapper;
import com.flash.InventoryManagement.service.SecurityAccrualStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/26
 */
@Service
public class SecurityAccrualStockServiceImpl implements SecurityAccrualStockService {
    @Autowired
    SecurityAccrualStockMapper securityAccrualStockMapper;

    @Override
    public int countSecurityStock() {
        return securityAccrualStockMapper.countSecurityAccrualStock();
    }

    @Override
    public List<SecurityAccrualStock> selectSecurityAccrualStock(SecurityAccrualStock securityAccrualStock, int page, int limit) {
        Map map =new HashMap();
        map.put("strWhere", buildWhere(securityAccrualStock));
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        return securityAccrualStockMapper.selectSecurityAccrualStock(map);
    }
        //增加
    @Override
    public int insertSecurityAccrualStock(SecurityAccrualStock securityAccrualStock) {
        return securityAccrualStockMapper.insertSecurityAccrualStock(securityAccrualStock);
    }
        //删除
    @Override
    public int deleteSecurityAccrualStock(SecurityAccrualStock securityAccrualStock) {
        return securityAccrualStockMapper.deleteSecurityAccrualStock(securityAccrualStock);
    }
        //修改
    @Override
    public int updateSecurityAccrualStock(SecurityAccrualStock securityAccrualStock) {
        return securityAccrualStockMapper.updateSecurityAccrualStock(securityAccrualStock);
    }


    public String buildWhere (SecurityAccrualStock securityAccrualStock) {
        StringBuffer strWhere = new StringBuffer();
        if (securityAccrualStock.getSecurityAccrualStockId()!=null && !securityAccrualStock.getSecurityAccrualStockId().equals("")){
            strWhere.append(" and securityAccrualStockId like '%" + securityAccrualStock.getSecurityAccrualStockId() +"%'" );
        }
        if (securityAccrualStock.getDateAccrualStock()!=null && !securityAccrualStock.getDateAccrualStock().equals("")){
            strWhere.append(" and dateAccrualStock like '%" + securityAccrualStock.getDateAccrualStock() +"%'" );
        }
        return strWhere.toString();
    }
}
